package com.atguigu.aliyunvod;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;
import org.junit.Test;

/**
 * @author dyqstart
 * @create 2021-07-10-23:29
 * @since 1.0.0
 */
public class VodSdkTest {

    public static DefaultAcsClient initVodClient(String accessKeyId, String accessKeySecret) {
        String regionId = "cn-shanghai"; // 点播服务接入区域
        DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
        DefaultAcsClient client = new DefaultAcsClient(profile);
        return client;
    }

    public static GetVideoPlayAuthResponse getVideoPlayAuth(DefaultAcsClient client) throws ClientException {
        GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
        request.setVideoId("31c8951adfb545b295cdd7b97a71a1ba");
        return client.getAcsResponse(request);
    }

    //以下为调用示例
    @Test
    public void testGetVideoPlayAuth() {
        DefaultAcsClient client = initVodClient("LTAI5tMG5Z3KMEXTeb36115H", "urfqoeqea0Xv5yuZ7Coa2m3KVFSzyD");
        GetVideoPlayAuthResponse response = new GetVideoPlayAuthResponse();

        try {
            response = getVideoPlayAuth(client);
            //播放凭证
            System.out.println("PlayAuth = " + response.getPlayAuth() + "\n");
            //VideoMeta信息
            System.out.println("VideoMeta.Title = " + response.getVideoMeta().getTitle() + "\n");
        } catch (ClientException e) {
            System.out.println("ErrorMessage = "+e.getLocalizedMessage());
        }

        System.out.println("RequestId = " + response.getRequestId() + "\n");
    }
}
